﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class SettingPanel : MonoBehaviour {

    public Slider BGMSlider;

    public Slider SESlider;

    public GameObject NormalPanel;
    

    public void Back()
    {
        StartCoroutine(GoToBack());
    }

    private IEnumerator GoToBack()
    {
        SESlider.GetComponent<AudioPro>().Play();
        yield return new WaitForSeconds(0.3f);
        if (NormalPanel != null)
        {
            NormalPanel.SetActive(true);
        }
        transform.GetChild(0).gameObject.SetActive(false);
    }

    public void SetSEVolume()
    {
        if ((int)(SettingManager.Instance.MainVolume*10) == (int)(SESlider.value))
        {
            return;
        }
        SettingManager.Instance.MainVolume = (SESlider.value / 10f);
        SESlider.GetComponent<AudioPro>().Play();
    }

    public void SetBGMVolume()
    {
        if ((int)(SettingManager.Instance.BackVolume*10) == (int)(BGMSlider.value))
        {
            return;
        }
        SettingManager.Instance.BackVolume = (BGMSlider.value / 10f);
        BGMSlider.GetComponent<AudioPro>().Play();
    }

    private void Awake()
    {
        transform.GetChild(0).gameObject.SetActive(false);
    }

    public void ToSetting()
    {
        if (NormalPanel != null)
        {
            NormalPanel.SetActive(false);
        }
        transform.GetChild(0).gameObject.SetActive(true);
        SESlider.value = (int)(SettingManager.Instance.MainVolume * 10);
        BGMSlider.value = (int)(SettingManager.Instance.BackVolume * 10);
    }

}
